<?php defined('BASEPATH') OR exit('No direct script access allowed');

class Agent extends Admin_Controller
{
    function __construct ()
    {
        parent::__construct();
        $this->config->load('userset');
        $this->load->library('pagination');
        $this->uid = $this->session->userdata('user_id');
    }

    public function index($page=1)
    {
        $limit = 30;
        $config['uri_segment'] = 4;
        $config['use_page_numbers'] = TRUE;
        $config['base_url'] = site_url('manage/bumen/index/');
        if(!$this->auth->is_super_admin()){
            $config['total_rows'] = $this->user_m->count_user_list_by(5,$this->uid);
        }else{
            $config['total_rows'] = $this->user_m->count_user_list_by(5);
        }
        $config['per_page'] = $limit;
        $config['num_links'] = 10;
        $this->pagination->initialize($config);
        $start = ($page-1)*$limit;
        $data['pagination'] = $this->pagination->create_links();
        if(!$this->auth->is_super_admin()){
            $list = $this->user_m->get_user_list_by(5,$start,$limit,$this->uid);
        }else{
            $list = $this->user_m->get_user_list_by(5,$start,$limit);
        }
        if(!empty($list)){
            foreach($list as $key => $value){
                if($value['sex'] == 1){
                    $list[$key]["sex"] = "男";
                }else{
                    $list[$key]["sex"] = "女";
                }
                if(empty($value['user_tel'])){
                    $list[$key]["user_tel"] = "---";
                }
                if(empty($value['agent_id'])){
                    $list[$key]["agent_id"] = "公众号";
                }else{
                    $user_arr = $this->user_m->get_user_by_user_id($value['agent_id']);
                    $list[$key]["agent_id"] = $user_arr['user_name'];
                }
                if(empty($value['user_dress'])){
                    $list[$key]["user_dress"] = "---";
                }

            }
        }
        $data['list'] = $list;
        $this->load->view('agent/index', $data);

    }

}
